﻿(function ($, window) {
	var defaultValues = {
		pageIndex: 1,
		pageSize: 100,
		pageCount: 1000,
		nextPageFunction: function (pageIndex, pageSize) { }
	};
	var isLastPage = false;//是否最后一页
	var isNextPage = true;

	window.TestDom = function () { }

	$.fn.InitialPage = function (config) {
	    config = $.extend(defaultValues, config);

		var dataFooterId = "dataFooterId";
		//添加一个结束div,当在浏览器的可视范围内的时候，加载数据
		var dataFooterDiv = document.createElement("div");
		dataFooterDiv.id = dataFooterId;
		dataFooterDiv.style.fontSize = 20;
		dataFooterDiv.innerHTML = "正在加载数据，请耐心等待！";
		this.after(dataFooterDiv);

		//$.ajaxSetup({ async: false });   //true:数据被IE缓存，改为false，每次都能取道新值。
		//监听滚动事件
		window.onscroll = function () {
			//判断是否在可视范围内
			var isVisual = dataFooterDiv.offsetTop >= $(window).scrollTop() && dataFooterDiv.offsetTop < ($(window).scrollTop() + $(window).height());

			if (isNextPage && !isLastPage && isVisual) {
				isNextPage = false;
				config.nextPageFunction(config.pageIndex, config.pageSize);
				if (config.pageCount / config.pageSize <= config.pageIndex) {
					isLastPage = true;
					dataFooterDiv.innerHTML = "这是最后一条数据。";
				}
				config.pageIndex += 1;
			}
		}
	}

	$.NextPage = function () {
	    isNextPage = true;
	}
	
	$.extend($.fn, { BmzTest: { Function3: function () { }, Function4: function () { } } });
	$.fn.extend(
	    {
	        
	            Function1: function () {
	                var item = this;

	                debugger;
	            },
	            Function2: function () { },
	    }
        );
    $.fn.BmzTestFunction=function(){}
})(jQuery,window)